package com.watson.todolist.database;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.watson.todolist.constants.DatabaseConstants;
import com.watson.todolist.to.TodoItem;

/**
 * The todo list manager class handles persisting todo items by directly
 * interacting with the database. A ToDoListManager object allows access to get
 * todo item data from the database and to put data inside of the database.
 * 
 * @author Donnie Ward
 * 
 * @since 1.0
 */
public class ToDoListManager {
	/**
	 * Logger tag
	 */
	private static String TAG = "ToDoListManager Class";
	/**
	 * Database instance
	 */
	private SQLiteDatabase db;

	/**
	 * This is the ToDoListManager that controls the database that contains all
	 * information about the to do list items.
	 * 
	 * @param db
	 */
	public ToDoListManager(SQLiteDatabase db) {
		this.db = db;
	}

	/**
	 * returns whether each to do list item is checked or not.
	 * 
	 * @param id
	 *            - the id of the to do item
	 * @return - whether the item is checked or not
	 */
	public boolean isChecked(long id) {

		Cursor cursor = db
				.query(true,
						DatabaseConstants.TODO_ITEM_TABLE_NAME,
						new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
						DatabaseConstants.ID + "=" + id, null, null, null,
						null, null);

		// Move cursor to first row
		if (cursor != null) {
			cursor.moveToFirst();
		}

		// checks to see if the cursor is null or has no rows(items)
		if (cursor == null || cursor.getCount() == 0) {
			return false;
		}

		// checks to see if item is checked or not
		int check = cursor
				.getInt(cursor
						.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED));
		if (check == 0) {
			return false;
		} else {
			return true;
		}

	}

	/**
	 * 
	 * This method creates a to do list item and adds it to the database
	 * 
	 * @param userId
	 *            - username
	 * @param todoItemName
	 *            - item name
	 * @param categoryCode
	 *            - category
	 * @param todoTime
	 *            - date of item
	 * @param latitude
	 *            - latitude of item
	 * @param longitude
	 *            - longititude of item
	 * @param description
	 *            - description of the item
	 * @param alarmRecurrenceType
	 *            - reoccurance of the item
	 * @param priorAlarmReminderTime
	 *            - priority of the item
	 * @param todoCompleted
	 *            - checked/unchecked of the item
	 * @return - returns the tag id of the item
	 */
	public long createTodoListItem(long userId, String todoItemName,
			int categoryCode, long todoTime, float latitude, float longitude,
			String description, int alarmRecurrenceType,
			long priorAlarmReminderTime, int todoCompleted) {

		ContentValues values = createContentValues(userId, todoItemName,
				categoryCode, todoTime, latitude, longitude, description,
				alarmRecurrenceType, priorAlarmReminderTime, todoCompleted);
		return db.insert(DatabaseConstants.TODO_ITEM_TABLE_NAME, null, values);
	}

	/**
	 * This method updates the to do list item by its item id
	 * 
	 * @param userId
	 *            - username
	 * @param todoItemName
	 *            - item name
	 * @param categoryCode
	 *            - category
	 * @param todoTime
	 *            - date of item
	 * @param latitude
	 *            - latitude of item
	 * @param longitude
	 *            - longititude of item
	 * @param description
	 *            - description of the item
	 * @param alarmRecurrenceType
	 *            - reoccurance of the item
	 * @param priorAlarmReminderTime
	 *            - priority of the item
	 * @param todoCompleted
	 *            - checked/unchecked of the item
	 * @return - returns the tag id of the item
	 */
	public boolean updateTodoListItemByTodoItemId(long todoItemId, long userId,
			String todoItemName, int categoryCode, long todoTime,
			float latitude, float longitude, String description,
			int alarmRecurrenceType, long priorAlarmReminderTime,
			int todoCompleted) {

		ContentValues values = createContentValues(userId, todoItemName,
				categoryCode, todoTime, latitude, longitude, description,
				alarmRecurrenceType, priorAlarmReminderTime, todoCompleted);

		return db.update(DatabaseConstants.TODO_ITEM_TABLE_NAME, values,
				DatabaseConstants.ID + "=" + todoItemId, null) > 0;
	}

	/**
	 * This method deletes a to do list item by its id
	 * 
	 * @param todoItemId
	 *            - the id of the item
	 * @return - if it was deleted or not
	 */
	public boolean deleteTodoListItemById(long todoItemId) {
		return db.delete(DatabaseConstants.TODO_ITEM_TABLE_NAME,
				DatabaseConstants.ID + "=" + todoItemId, null) > 0;
	}

	/**
	 * this method gets the to do list item by the to do id and returns that
	 * item
	 * 
	 * @param todoItemId
	 * @return the to do list item
	 */
	public TodoItem getTodoListItemByTodoId(long todoItemId) {
		Cursor cursor = db
				.query(true,
						DatabaseConstants.TODO_ITEM_TABLE_NAME,
						new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
						DatabaseConstants.ID + "=" + todoItemId, null, null,
						null, null, null);

		// Move cursor to first row
		if (cursor != null) {
			cursor.moveToFirst();
		}

		// Check to see if any rows are in cursor
		if (cursor == null || cursor.getCount() == 0) {
			Log.d(TAG,
					"No rows contained in cursor in getTodoListItemByTodoId()");
			return null;
		}

		// Begin population of todo item
		TodoItem todoItem = new TodoItem();
		todoItem.setDescription(cursor.getString(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION)));
		todoItem.setLatitude(cursor.getFloat(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE)));
		todoItem.setLongitude(cursor.getFloat(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE)));
		todoItem.setAlarmRecurrenceType(cursor.getInt(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE)));
		todoItem.setPriorAlarmReminderTime(cursor.getLong(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME)));
		todoItem.setTodoCompleted(cursor.getInt(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED)));
		todoItem.setTodoItemCategoryCode(cursor.getInt(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE)));
		todoItem.setTodoItemId(cursor.getLong(cursor
				.getColumnIndex(DatabaseConstants.ID)));
		todoItem.setTodoItemName(cursor.getString(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME)));
		todoItem.setTodoTime(cursor.getLong(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME)));
		todoItem.setUserId(cursor.getLong(cursor
				.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_USER_ID)));

		return todoItem;
	}

	/**
	 * This method gets all the matched items with completed checkboxes and
	 * returns that cursor
	 * 
	 * @param userId
	 * @param completed
	 * @param categoryCode
	 * @param todoTime
	 * @return returns the cursor that stores the list of items
	 */
	public Cursor getAllMatchesWithCompletedCriteriaIncluded(long userId,
			int completed, int categoryCode, long todoTime) {
		Cursor cursor;
		if (categoryCode != 0) {	//category specified
			cursor = db
					.query(true,
							DatabaseConstants.TODO_ITEM_TABLE_NAME,
							new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID
								+ "="
								+ userId
								+ " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED
								+ "="
								+ completed
								+ " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE
								+ "=" + categoryCode + " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME
								+ ">" + todoTime, null, null, null, null, null);
		}
		else {		//no category specified
			cursor = db
					.query(true,
							DatabaseConstants.TODO_ITEM_TABLE_NAME,
							new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID
								+ "="
								+ userId
								+ " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED
								+ "="
								+ completed
								+ " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME
								+ ">" + todoTime, null, null, null, null, null);
		}
		// Move cursor to first row
		if (cursor != null) {
				cursor.moveToFirst();
		}

		// Check to see if any rows are in cursor
		if (cursor == null || cursor.getCount() == 0) {
			Log.d(TAG,
					"No rows contained in cursor in getAllMatchesWithCompletedCriteriaIncluded()");
			return null;
		}
		return cursor;
	}

	/**
	 * This method gets all the matches of to do list items without checking the state
	 * of the check boxes (gives both checked and unchecked values)
	 * 
	 * @param userId
	 * @param categoryCode
	 * @param todoTime
	 * @return returns the cursor containing the to do list items that matched
	 */
	public Cursor getAllMatchesWithOutCompletedCriteriaIncluded(long userId,
			int categoryCode, long todoTime) {
		Cursor cursor;
		if (categoryCode != 0) {
			cursor = db
				.query(true,
						DatabaseConstants.TODO_ITEM_TABLE_NAME,
						new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
						DatabaseConstants.TODO_ITEM_TABLE_USER_ID
								+ "="
								+ userId
								+ " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE
								+ "=" + categoryCode + " AND "
								+ DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME
								+ ">" + todoTime, null, null, null, null, null);

		}
		else {
			cursor = db
					.query(true,
							DatabaseConstants.TODO_ITEM_TABLE_NAME,
							new String[] {
									DatabaseConstants.ID,
									DatabaseConstants.TIME_STAMP,
									DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
									DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
									DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
									DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
									DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
									DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
									DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
									DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
									DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
									DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
							DatabaseConstants.TODO_ITEM_TABLE_USER_ID
									+ "="
									+ userId
									+ " AND "
									+ DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME
									+ ">" + todoTime, null, null, null, null, null);
		}
			// Move cursor to first row
		if (cursor != null) {
			cursor.moveToFirst();
		}

		// Check to see if any rows are in cursor
		if (cursor == null || cursor.getCount() == 0) {
			Log.d(TAG,
					"No rows contained in cursor in getAllMatchesWithOutCompletedCriteriaIncluded()");
			return null;
		}
		return cursor;
	}

	/**
	 * This method takes a userId and finds the date of the first occuring todo item
	 * from that user's entire list of todo items.
	 * 
	 * @param userId
	 * @return the first occuring date
	 */
	public long getFirstDateByUserId(long userId) {
		List<TodoItem> items = getAllTodoListItemsByUserId(userId);
		if (items == null)
			return 0;
		long firstDate = items.get(0).getTodoTime();
		for (TodoItem item: items) {
			if (item.getTodoTime() < firstDate)
				firstDate = item.getTodoTime();
		}
		return firstDate;
	}
	
	/**
	 * This method takes a userId and finds the date of the last occuring todo item
	 * from that user's entire list of todo items.
	 * 
	 * @param userId
	 * @return the last occuring date
	 */
	public long getLastDateByUserId(long userId) {
		List<TodoItem> items = getAllTodoListItemsByUserId(userId);
		if (items == null)
			return 0;
		long lastDate = items.get(0).getTodoTime();
		for (TodoItem item: items) {
			if (item.getTodoTime() > lastDate)
				lastDate = item.getTodoTime();
		}
		return lastDate;
	}
	
	/**
	 * this method returns all the items that the user has created
	 * 
	 * @param userId
	 *            - the user id of the user
	 * @return - list of all to do list items
	 */
	public List<TodoItem> getAllTodoListItemsByUserId(long userId) {
		Cursor cursor = db
				.query(true,
						DatabaseConstants.TODO_ITEM_TABLE_NAME,
						new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
						DatabaseConstants.TODO_ITEM_TABLE_USER_ID + "="
								+ userId, null, null, null, null, null);

		// Move cursor to first row
		if (cursor != null) {
			cursor.moveToFirst();
		}

		// Check to see if any rows are in cursor
		if (cursor == null || cursor.getCount() == 0) {
			Log.d(TAG,
					"No rows contained in cursor in getAllTodoListItemsByUserId()");
			return null;
		}

		// Populate todo items and put into a list
		List<TodoItem> todoItemList = new ArrayList<TodoItem>();
		while (!cursor.isAfterLast()) {
			TodoItem todoItem = new TodoItem();
			todoItem.setDescription(cursor.getString(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION)));
			todoItem.setLatitude(cursor.getFloat(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE)));
			todoItem.setLongitude(cursor.getFloat(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE)));
			todoItem.setAlarmRecurrenceType(cursor.getInt(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE)));
			todoItem.setPriorAlarmReminderTime(cursor.getLong(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME)));
			todoItem.setTodoCompleted(cursor.getInt(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED)));
			todoItem.setTodoItemCategoryCode(cursor.getInt(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE)));
			todoItem.setTodoItemId(cursor.getLong(cursor
					.getColumnIndex(DatabaseConstants.ID)));
			todoItem.setTodoItemName(cursor.getString(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME)));
			todoItem.setTodoTime(cursor.getLong(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME)));
			todoItem.setUserId(cursor.getLong(cursor
					.getColumnIndex(DatabaseConstants.TODO_ITEM_TABLE_USER_ID)));

			todoItemList.add(todoItem);
			cursor.moveToNext();
		}
		return todoItemList;
	}

	/**
	 * This method returns the cursor that holds all the to do list items by the
	 * user id
	 * 
	 * @param userId
	 * @return the cursor that holds the matched items
	 */
	public Cursor getAllTodoListItemsInCursorByUserId(long userId) {
		Cursor cursor = db
				.query(true,
						DatabaseConstants.TODO_ITEM_TABLE_NAME,
						new String[] {
								DatabaseConstants.ID,
								DatabaseConstants.TIME_STAMP,
								DatabaseConstants.TODO_ITEM_TABLE_USER_ID,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
								DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
								DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
								DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED },
						DatabaseConstants.TODO_ITEM_TABLE_USER_ID + "="
								+ userId, null, null, null, null, null);

		// Move cursor to first row
		if (cursor != null) {
			cursor.moveToFirst();
		}
		return cursor;
	}

	/**
	 * This method creates the content values of the to do item
	 * 
	 * @param userId
	 *            - username
	 * @param todoItemName
	 *            - item name
	 * @param categoryCode
	 *            - category
	 * @param todoTime
	 *            - date of item
	 * @param latitude
	 *            - latitude of item
	 * @param longitude
	 *            - longitude of item
	 * @param description
	 *            - description of the item
	 * @param alarmRecurrenceType
	 *            - Recurrence of the item
	 * @param priorAlarmReminderTime
	 *            - priority of the item
	 * @param todoCompleted
	 *            - checked/unchecked of the item
	 * @return - content values of the items
	 */
	private ContentValues createContentValues(long userId, String todoItemName,
			int categoryCode, long todoTime, float latitude, float longitude,
			String description, int alarmRecurrenceType,
			long priorAlarmReminderTime, int todoCompleted) {

		ContentValues values = new ContentValues();
		values.put(DatabaseConstants.TODO_ITEM_TABLE_USER_ID, userId);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_TODO_ITEM_NAME,
				todoItemName);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_CATEGORY_CODE,
				categoryCode);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_TODO_TIME, todoTime);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LATITUDE,
				latitude);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_LOCATION_LONGITUDE,
				longitude);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_DESCRIPTION, description);
		values.put(
				DatabaseConstants.TODO_ITEM_TABLE_TODO_ALARM_RECURRENCE_TYPE,
				alarmRecurrenceType);
		values.put(
				DatabaseConstants.TODO_ITEM_TABLE_TODO_PRIOR_ALARM_REMINDER_TIME,
				priorAlarmReminderTime);
		values.put(DatabaseConstants.TODO_ITEM_TABLE_TODO_COMPLETED,
				todoCompleted);
		return values;
	}
}